`
https://leetcode.cn/problems/shortest-subarray-to-be-removed-to-make-array-sorted/
`

/**
 * @param {number[]} arr
 * @return {number}
 */
var findLengthOfShortestSubarray = function (arr) {
  const n = arr.length
  let right = n - 1
  // 找右边的递增数组
  while (right > 0 && arr[right] >= arr[right - 1]) right--
  // 数组已经非递减的了
  if (right === 0) return 0
  // 删除 arr[:right]
  let res = right
  let left = 0
  while (left === 0 || arr[left - 1] <= arr[left]) {
    while (right < n && arr[right] < arr[left]) {
      right++
    }
    // 此时 arr[left] <= arr[right]，删除 arr[left+1:right]
    res = Math.min(res, right - left - 1)
    left++
  }
  return res
};